<template>
  <PageWrapper :contentStyle="{ margin: '10px' }" class="site-config">
    <Card title="基础收费" style="width: 100%">
      <div class="columns-3">
        <div v-for="(item, index) in dataList" :v-key="item.name" class="flex mb-5">
          <div class="flex-initial w-32 div-40 div-title">
            <Tooltip placement="topLeft" :title="item.label">
              {{ item.label }}
            </Tooltip>
          </div>
          <div class="div-40 mr5 div-s">:</div>
          <Input :value="item.value" class="flex-initial w-60" :disabled="true" :size="'large'">
            <!-- <template #addonAfter>
              {{ item.unit }}
            </template> -->
            <template #addonAfter>
              <div>
                <cdIconCurrency :icon="'USDT'" class="w-20px" />
                {{ item.unit }}
              </div>
            </template>
          </Input>
        </div>
      </div>
    </Card>
  </PageWrapper>
</template>
<script lang="ts" setup>
  import { onMounted, ref } from 'vue';
  import { PageWrapper } from '@/components/Page';
  import { Card, Input, Tooltip } from 'ant-design-vue';
  import { configList } from '@/api/sys';
  import cdIconCurrency from '/@/components-cd/Icon/currency/cd-icon-currency.vue';

  const dataList = ref();
  const dataLabel = {
    sid: '站点ID',
    line_fee: '线路维护费',
    cdn_fee: 'CDN超额收费',
    domain_fee: '域名额外收费',
    code: '站点编号',
    bond: '站点押金',
    overdraft: '最大透支额度',
    site_fee: '开站费用',
  };
  const dataUnit = {
    sid: '',
    line_fee: 'USDT',
    cdn_fee: 'USDT/1GB',
    domain_fee: 'USDT/个',
    code: '',
    bond: 'USDT',
    overdraft: 'USDT',
    site_fee: 'USDT',
  };
  const GetCostDetail = async () => {
    const data = await configList();
    let arrData = [];
    for (let i = 0; i < Object.entries(data).length; i++) {
      var item = {};
      if (Object.entries(data)[i]) {
        item['name'] = Object.entries(data)[i][0];
        item['value'] = Object.entries(data)[i][1];
        item['label'] = dataLabel[item['name']];
        item['unit'] = dataUnit[item['name']];
      }
      if (item['unit']) {
        arrData.push(item);
      }
    }
    const arr = arrData.map((item: any, index) => {
      return {
        id: index,
        ...item,
      };
    });
    dataList.value = arr;
    let customOrder = [0, 5, 1, 3, 2, 4];

    // 创建一个映射表
    let orderMap = {};
    customOrder.forEach((id, index) => {
      orderMap[id] = index;
    });
    arr.sort((a, b) => orderMap[a.id] - orderMap[b.id]);
  };
  const table = ref();
  onMounted(() => {
    GetCostDetail();
  });
</script>
<style scoped>
  .div-40 {
    height: 40px;
    overflow: hidden;
    line-height: 1;
    text-overflow: ellipsis;
    white-space: nowrap;

    .ant-input {
      height: 40px;
    }
  }

  .div-title {
    padding: 3px;
    padding-top: 10px;
    text-align: right;
  }

  .div-s {
    padding-top: 10px;
  }

  ::v-deep(.ant-input-disabled) {
    border-color: #dce3f1;
    background-color: #f6f7fb !important;
  }

  ::v-deep(.ant-input-group-addon-disabled) {
    border-color: #dce3f1;
    background-color: #dce3f1 !important;
  }
</style>
